<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="mall/header::head-fragment('Magic_Coffee咖啡店-个人中心','user-center')">
</head>
<body>
<header th:replace="mall/header::header-fragment"></header>
<nav th:replace="mall/header::header-search-fragment"></nav>
<div class="crumb">
    <div class="w">
        <div class="crumb-con">
            <a href="./index.html" class="link">Mall</a>
            <span>></span>
            <span class="link-text">修改密码</span>
        </div>
    </div>
</div>
<div class="page-wrap w">
    <!--左边导航栏-->
    <div th:replace="mall/nav-side::nav-side-fragment"></div>
    <div class="content with-nav">
        <div class="panel" >
            <div class="panel-title">修改密码</div>
            <div class="panel-body">
                <div class="user-info">
                        <div class="form-line">
                            <span class="label">原密码：</span>
                            <input type="password" class="input" id="password" autocomplete="off"></input>
                        </div>
                        <div class="form-line">
                            <span class="label">新密码：</span>
                            <input type="password" class="input" id="passwordNew" autocomplete="off"></input>
                        </div>
                        <div class="form-line">
                            <span class="label">确认密码：</span>
                            <input type="password" class="input" id="passwordConfirm" autocomplete="off"></input>
                        </div>
                        <button type="submit" class="btn btn-submit">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:replace="mall/general-footer::general-footer-fragment"></div>
</body>
<!-- jQuery -->
<!--<script th:src="@{/admin/plugins/jquery/jquery.min.js}"></script>-->
<script th:src="@{/admin/plugins/jquery/jquery-3.5.1.min.js}"></script>
<script th:src="@{/admin/dist/js/public.js}"></script>
<script th:src="@{/admin/plugins/sweetalert/sweetalert.min.js}"></script>
<!--<script type="text/javascript" th:src="@{/mall/js/user/user-center.js}"></script>-->
<script type="text/javascript">
    $(function () {
        $('#userPassUpdate').addClass('active');
    });
    $(document).on('click','.btn-submit',function () {
        var password = $.trim($('#password').val());
        if (!validPassword(password)) {
            swal('请输入6-20位字符和数字组合的密码', {
                icon: "error",
            });
            return false;
        }
        var passwordNew = $.trim($('#passwordNew').val());
        if (!validPassword(passwordNew)) {
            swal('请输入6-20位字符和数字组合的密码', {
                icon: "error",
            });
            return false;
        }
        var passwordConfirm = $.trim($('#passwordConfirm').val());
        if (passwordConfirm != passwordNew) {
            swal('两次输入的密码不一致！', {
                icon: "error",
            });
            return false;
        }

/*        var userInfo = {
            phone : phone,
            email : email,
            question : question,
            answer : answer
        };*/

        $.ajax({
            type : 'POST',
            url :'/user-pass-update',
            // contentType : 'application/json',
            data : {
                passwordOld : password,
                passwordNew : passwordNew
            },
            success : function (result) {
                if (result.resultCode == 200){
                    alert("个人密码修改成功！");
                    window.location.reload();
                }else{
                    alert(result.message);
                }
            },
            error : function (result) {
                alert("操作失败");
            }
        });
    });
</script>
</html>